#ifndef TCPSEGMENT_H
#define TCPSEGMENT_H
#include <stdint.h>
#include "public.h"
#include "ip.h"
#include "tcp.h"

struct tha {
    struct in_addr src;
    struct in_addr dst;
    u_int port;
    friend bool operator<(const tha &tha1, const tha&tha2)
    {
        uint64_t addr1 = (uint64_t)tha1.src.s_addr << 32 | tha1.src.s_addr;
        uint64_t addr2 = (uint64_t)tha2.src.s_addr << 32 | tha2.src.s_addr;

        if(addr1 < addr2)
        {
            return true;
        }
        else if(addr1 == addr2 && tha1.port < tha2.port)
        {
            return true;
        }
        else
        {
            return false;
        }

    }
};

class TCPSegment
{
    const struct tcphdr *tp;
    const struct ip *ip;
    uint16_t win;
    uint16_t urp;
    u_int fragmented;
    u_int length;
    u_char flags;
public:
    tcp_seq seq;
    tcp_seq ack;
    struct tha tha;
    int rev;
    u_char *payload;
    u_int payloadlen;

public:
    TCPSegment(const u_char *tcp_begin, u_int len, const u_char *ip, u_int fragmented);
    int dissection();
};

#endif // TCPSEGMENT_H
